package com.abocode.aichat.configuration;
import com.abocode.aichat.getway.endpoint.GatewayEndpoint;
import com.abocode.aichat.getway.modules.GatewayModule;
import com.abocode.aichat.getway.worker.GatewayStanzaWorker;
import com.abocode.aichat.server.context.ServerRuntimeContext;
import com.abocode.aichat.server.modules.Module;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

import java.util.ArrayList;
import java.util.List;

//@Configuration
public class GatewayConfiguration {
    @Value("${im.domain}")
    private  String domain;
    @Value("${im.port}")
    private  int port;
    @Autowired
    private ServerRuntimeContext serverRuntimeContext;

    @Bean(initMethod = "start",destroyMethod = "shutdown")
    public GatewayEndpoint gatewayEndpoint(){
        GatewayEndpoint endpoint=new GatewayEndpoint();
        endpoint.setName("protocol");
        endpoint.setModules(modules());
        endpoint.setDomain(domain);
        endpoint.setPort(port);
        endpoint.setChildSize(100);
        endpoint.setParentSize(100);
        endpoint.setServerRuntimeContext(serverRuntimeContext);
        endpoint.setWorker(worker());
        return endpoint;
    }
    @Bean
   public GatewayStanzaWorker worker(){
        return  new GatewayStanzaWorker();
    }
    @Bean
    public List<Module> modules(){
        List<Module> modules=new ArrayList();
        modules.add(gatewayModule());
        return modules;
    }

    @Bean
    public GatewayModule gatewayModule(){
        return  new GatewayModule();
    }


}
